﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class randomImageCtl : System.Web.UI.UserControl
{
    public bool isOk
    {
        get
        {
            if (randValue.ToLower() == txtValue.Text.ToLower())
                return true;
            else
                return false;

        }
    }
    
    
    Random rndNew = new Random((int)DateTime.Now.ToFileTime());

    
    public string pageID
    {
        get
        {
            if (ViewState["pageID"] == null)
                ViewState["pageID"] = System.Guid.NewGuid().ToString();

            string strRet = "";
            strRet = ViewState["pageID"].ToString();

            return strRet;
            
        }
        set
        {
            ;

            ViewState["pageID"] = value;
        }
    }


    public string randValue
    {
        get {

            

            string strRet = "";

            if (Session[pageID + "_randImage"] == null)
            {
                Session[pageID + "_randImage"] = System.Guid.NewGuid().ToString();
            }

            strRet = Session[pageID + "_randImage"].ToString();
            return strRet;
            
            
             }
        
    }




    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            Page.DataBind();
        }

    }
    protected void lnkChange_Click(object sender, EventArgs e)
    {
        pageID = System.Guid.NewGuid().ToString();
        Page.DataBind();

    }



    protected string getImageUrl()
    {

        int num = 0;
        num = rndNew.Next(4, 8);


        return "getRandomImage.ashx?id=" + pageID + "&font=20&num=" + num;
    }

    public void clear()
    {
        txtValue.Text = "";

        lnkChange_Click(null, null);

    }
}
